<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <custom-input
        show-clear
        placeholder="请输入用户名："
        v-model="userName"
      ></custom-input
      >{{userName}}
      <custom-input
        label="密码"
        placeholder="请输入密码"
        type="password"
        v-model="password"
      ></custom-input
      >{{password}}
    </div>
    <template id="input">
      <div>
        <label>{{label}}</label>
        <input
          :type="type"
          :value="value"
          :placeholder="placeholder"
          @input="$emit('input',$event.target.value)"
        />
        <span v-if="value !=='' && showClear" @click="$emit('input','')"
          >X-UA-Compatible</span
        >
      </div>
    </template>

    <script src="../lib/vue.js"></script>
    <script>
      const Input = {
        template: "#input",
        props: {
          value: String | Number,
          type: {
            type: {
              type: String,
              default: "text",
            },
            placeholder: {
              type: String,
              defualt: "请输入关键词",
            },
            label: String,
            showClear: Boolean,
          },
        },
      };

      new Vue({
        data: {
          userName: "",
          password: "",
        },
        methods: {
          getData(val) {
            console.log(val);
            this.userName = val;
          },
        },
        components: {
          CustomInput: Input,
        },
      }).$mount("#app");
    </script>
  </body>
</html>
